﻿'Imports System.Xml
'Imports System.Web.Services.Protocols

'Public Class WebServices

'    Public Enum FaultCode
'        Client = 0
'        Server = 1
'    End Enum

'    ''' <summary>Throws a SoapException to the WebService Client.</summary>
'    ''' <remarks>
'    '''    <para>Got from <a href=
'    '''    "http://www.developer.com/net/csharp/article.php/10918_3088231_1">http://www.developer.com/net/csharp/article.php/10918_3088231_1</a>.</para>
'    '''    <para>Not tested.</para>
'    ''' </remarks>
'    ''' <example>
'    '''    Throwing and handling SoapExceptions.
'    '''    <code lang="CS" title="Throwing a SoapException from the server">
'    ''' Throw
'    ''' RaiseException("AddCategories",
'    ''' "http://tempuri.org/CategoriesService",
'    ''' builder.ToString(),
'    ''' "2000","AddCategories",FaultCode.Client);
'    ''' </code>
'    '''	<code lang="CS" title="Handling a SoapException from the client">
'    ''' MessageBox.Show(soapEx.Code.ToString());
'    '''   //Load the Detail element of the SoaopException object
'    '''   XmlDocument doc = new XmlDocument();
'    '''   doc.LoadXml(soapEx.Detail.OuterXml);
'    '''   XmlNamespaceManager nsManager = new
'    '''     XmlNamespaceManager(doc.NameTable);
'    '''   // Add the namespace to the NamespaceManager
'    '''   nsManager.AddNamespace("errorNS",
'    '''     "http://tempuri.org/CategoriesService");
'    '''   XmlNode categoryNode =
'    '''     doc.DocumentElement.SelectSingleNode("errorNS:Error",
'    '''                                          nsManager);
'    '''   string errorNumber = 
'    '''     categoryNode.SelectSingleNode("errorNS:ErrorNumber",
'    '''                                   nsManager).InnerText;
'    ''' string errorMessage = 
'    ''' categoryNode.SelectSingleNode("errorNS:ErrorMessage",
'    '''                               nsManager).InnerText;
'    ''' string errorSource = 
'    ''' categoryNode.SelectSingleNode("errorNS:ErrorSource",
'    '''                               nsManager).InnerText;
'    '''   MessageBox.Show("Error Number is" +  errorNumber);
'    '''   MessageBox.Show("Error Message is" + errorMessage);
'    '''   MessageBox.Show("Error Source is" + errorSource);
'    ''' </code>
'    ''' </example>
'    ''' <requirements><c>System.Xml</c> namespace</requirements>
'    ''' <isnew>09/05/2008 18.27.00</isnew>
'    ''' <keywords>not tested</keywords>
'    ''' <param name="uri">URL of the Web service method where the exception occured.</param>
'    ''' <param name="errorMessage">Message of the Exception</param>
'    ''' <param name="code">
'    ''' Specifies if the error is server side (means a problem on the server) or client
'    ''' side (means a problem on the parameters got from the client).
'    ''' </param>
'    Public Shared Function ThrowSoapException(ByVal uri As String, ByVal webServiceNamespace As String, ByVal errorMessage As String, ByVal errorNumber As String, ByVal errorSource As String, ByVal code As FaultCode) As SoapException
'        Dim faultCodeLocation As XmlQualifiedName = Nothing
'        'Identify the location of the FaultCode
'        Select Case code
'            Case FaultCode.Client
'                faultCodeLocation = SoapException.ClientFaultCode
'                Exit Select
'            Case FaultCode.Server
'                faultCodeLocation = SoapException.ServerFaultCode
'                Exit Select
'        End Select
'        Dim xmlDoc As New XmlDocument()
'        'Create the Detail node
'        Dim rootNode As XmlNode = xmlDoc.CreateNode(XmlNodeType.Element, SoapException.DetailElementName.Name, SoapException.DetailElementName.[Namespace])
'        'Build specific details for the SoapException
'        'Add first child of detail XML element.
'        Dim errorNode As XmlNode = xmlDoc.CreateNode(XmlNodeType.Element, "Error", webServiceNamespace)
'        'Create and set the value for the ErrorNumber node
'        Dim errorNumberNode As XmlNode = xmlDoc.CreateNode(XmlNodeType.Element, "ErrorNumber", webServiceNamespace)
'        errorNumberNode.InnerText = errorNumber
'        'Create and set the value for the ErrorMessage node
'        Dim errorMessageNode As XmlNode = xmlDoc.CreateNode(XmlNodeType.Element, "ErrorMessage", webServiceNamespace)
'        errorMessageNode.InnerText = errorMessage
'        'Create and set the value for the ErrorSource node
'        Dim errorSourceNode As XmlNode = xmlDoc.CreateNode(XmlNodeType.Element, "ErrorSource", webServiceNamespace)
'        errorSourceNode.InnerText = errorSource
'        'Append the Error child element nodes to the root detail node.
'        errorNode.AppendChild(errorNumberNode)
'        errorNode.AppendChild(errorMessageNode)
'        errorNode.AppendChild(errorSourceNode)
'        'Append the Detail node to the root node
'        rootNode.AppendChild(errorNode)
'        'Construct the exception
'        Dim soapEx As New SoapException(errorMessage, faultCodeLocation, uri, rootNode)
'        'Raise the exception  back to the caller
'        Return soapEx
'    End Function

'End Class
